#!/bin/bash
UNAME=`which uname`
HOSTNAME_CMD=`which hostname`
FDISK=`which fdisk`
FREE=`which free`
UNAME=`which uname`
UPTIME=`which uptime`

SN=`cat /sys/class/dmi/id/product_serial|sed 's/ //g'`|| SN='NO_Sernumber'
Release_Date=`cat /sys/class/dmi/id/bios_date`|| Release_Date='01/01/1980'
VENDOR=`cat /sys/class/dmi/id/bios_vendor|awk '{print $1}' `|| VENDOR='NO_Vendor'
MODEL=`cat /sys/class/dmi/id/product_name`|| MODEL='NO_Product'
CPU_NUM=`cat /proc/cpuinfo| grep "physical id"|sort| uniq| wc -l`||CPU_NUM=1
CPU_CORES=`cat /proc/cpuinfo| grep "cpu cores"| uniq|awk -F ":" '{print $2}'` || CPU_CORES=1
CPU_MODEL=`cat /proc/cpuinfo | grep "model name"|uniq |cut -f2 -d:`
CPU_PRO=`grep ^processor /proc/cpuinfo |wc -l`||CPU_PRO=1
DISK_SIZE=`$FDISK -l 2>/dev/null |grep "Disk"|grep bytes|grep -v "VolGroup"|grep -v "mapper"| awk '{print $3"G"}'`
MEM_SIZE=`$FREE -m|grep Mem|awk '{if ($2<1024) print substr($2,1,3)"M";else if ($2<10240 && $2>1024) print substr($2/1024,1,3)"G";else print substr($2/1024,1,4)"G"}'`
UPTIME=`$UPTIME |awk '{if (match($0,"day")!=0) print $3;else print 0}'`
###############################check-sys-base#################################
if [[ -f '/etc/debian_version' ]];then
	if grep -q Ubuntu /etc/issue;then
		OS=`head -1 /etc/issue|awk '{print $1"_"$2}'`
	else
		OS="Debian_"`cat /etc/debian_version`
	fi
elif [[ -f '/etc/redhat-release' ]];then
	OS=`cat /etc/redhat-release|sed 's/Linux\|Server\|release\|Enterprise//g'|sed 's/[ ][ ]*/_/g'|sed 's/([^)]*)//g'|sed 's/_*$//g'|awk -F '.' '{print $1"."$2}'`
else 
	OS="Unkown"
fi
KERNEL=`$UNAME -r`
HOSTNAME=`$HOSTNAME_CMD`
IPS=`ip -4 address | grep ' inet ' | grep -vE '127.0.0.1|docker0|tun' |awk '{print $2}'|awk -F '/' '{print $1}'`

echo \"devinfo\":\{\
	\"SN\":\"$SN\",\
	\"Uptime\":\"$UPTIME\",\
	\"HostName\":\"$HOSTNAME\",\
	\"Release_Date\":\"$Release_Date\",\
	\"Vendor\":\"$VENDOR\",\
	\"Model\":\"$MODEL\",\
	\"Cpu_Model\":\"$CPU_MODEL\",\
	\"Cpu_Num\":\"$CPU_NUM\",\
	\"Cpu_Cores\":\"$CPU_CORES\",\
	\"Cpu_Pro\":\"$CPU_PRO\",\
	\"Disk\":\"$DISK_SIZE\",\
	\"Memory\":\"$MEM_SIZE\",\
	\"OS\":\"$OS\",\
	\"Kernel\":\"$KERNEL\",\
	\"Ips\":\"$IPS\"\
	\}
